<?php

namespace app\service;

use app\model\RegisterModel;

class RegisterService
{

    // 账号密码注册
    public function Register($req){
        $phone = $req['phone'];
        $pwd = $req['pwd'];
        $newPwd = md5($pwd);
        $user = RegisterModel::seletByPhone($phone);
        //print_r($user);exit();
        if (empty($user)){
            //echo '1';exit();
            throw new \Think\Exception('手机号已被注册');
        }
        //echo '2';exit();
        $data= [
            'name'=>$phone,
            'phone'=>$phone,
            'pwd'=>$newPwd,
            'state'=>'1'
        ];
        $ins = RegisterModel::insertUser($data);
        //echo $ins.'爱莎事情';exit();
        if ($ins==0){
            throw new \Think\Exception('注册失败请重试');
        }
        return '注册成功';
    }
}